local lhs_vars linstall CollPerc_t Pol_t sub_ben tot_ben linstall_perc_pop linstallSim install_perc_pop linstall_perc_pop_Sim Inc_t linstall_perc_DS linstall_perc_DS_Sim lpanels_perc_DS lpanels_perc_DS_Sim

local bin_width=5 //5 //100/15
local bin_width_big=10

local graphs 0

local max_dist 50

local life $life

local ave_panels $ave_panels

local r $r
local deprate $deprate

local graphs 0

local KW_per_panel=$KW_per_panel
* https://news.energysage.com/how-many-solar-panels-do-i-need/
pause off

clear


use ../Data/CleanedData/MergedData2, clear



gen install_perc_pop=BI_t/population 

gen linstall_perc=log(install_perc)
gen linstall_perc_pop=log(install_perc_pop)

gen linstall_perc_DS=log(BI_t/HH_tract)
gen linstall_perc_DS_Sim=log(BI_t_pred/HH_tract)

gen lpanels_perc_DS=log(M_t/HH_tract)
gen lpanels_perc_DS_Sim=log(M_t_pred/HH_tract)



gen linstallSim=log(BI_t_pred)

gen linstall_perc_pop_Sim=log(BI_t_pred/population)

//gen Inc_t=average_household_income




drop _merge
** merge to border data
merge 1:1 region_name using  ../Data/CleanedData/TractDistancesXXwalk

drop if _merge==2

replace distance=9999999 if _m!=3
* gives distance to border and border

bysort border: egen A_bar=mean(A_t)

gen kwh_ben_bar=skwh*A_bar * `ave_panels'
gen sub_ben_bar=kwh_ben_bar+cost_ben+unit_ben

gen price_ben_bar=price*A_bar*`ave_panels'

gen tot_ben_bar=price_ben_bar+kwh_ben_bar-cost+cost_ben+unit_ben




*foreach type in sub tot {
local type sub  //sub //tot

bysort border: egen max_`type'_ben=max(`type'_ben_bar)
bysort border: egen min_`type'_ben=min(`type'_ben_bar)


gen novar_`type'=abs(max_`type'_ben-min_`type'_ben)<1 // these provide no variation so we don't want to use them. Don't 

bysort border: gen num=_n

tab novar_`type' if num==1



gen highside_`type'=abs(`type'_ben_bar-max_`type'_ben)<1
gen lowside_`type'=abs(`type'_ben_bar-min_`type'_ben)<1

tab highside_`type' if novar_`type'==0 & distance<100
tab lowside_`type' if novar_`type'==0 & distance<100



gen dist_loc_`type'=distance

replace dist_loc_`type'=-dist_loc_`type' if lowside_`type'==1

gen bin_`type'=ceil(dist_loc_`type'/`bin_width')

sum bin_`type' if distance<`max_dist'

local min_bin=r(min)
local max_bin=r(max)

cap drop bin_temp

gen bin_temp=100+bin_`type'


gen bin_`type'_big=ceil(dist_loc_`type'/`bin_width_big')

sum bin_`type'_big if distance<`max_dist'

local min_bin_big=r(min)
local max_bin_big=r(max)





gen bin_temp_big=100+bin_`type'_big

/*
gen statefips=state_fips

drop _merge
merge m:1 statefips  using suppdata/stateRates

keep if _merge==3
*/


**********************Now run regressions to make plots*********************
foreach var  of local lhs_vars {  //in linstall CollPerc_t Pol_t sub_ben tot_ben linstall_perc_pop linstall_perc_pop_Sim {
*local var linstall_perc_pop


* reg `var'  ib100.bin_temp i.border if distance<=`max_dist' & novar_`type'==0 [aw=number_of_panels_total]

areg `var'  ib100.bin_temp stateTax  if distance<`max_dist' & novar_`type'==0 [aw=number_of_panels_total], absorb(border)

local min_bin_temp=`min_bin'
local max_bin_temp=`max_bin'

if "`var'"=="lpanels_perc_DS" | "`var'"=="lpanels_perc_DS_sim" | "`var'"=="linstall_perc_DS"  | "`var'"=="linstall_perc_pop_Sim"  {
	areg `var'  ib100.bin_temp_big CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg if distance<=`max_dist' & novar_`type'==0 [aw=number_of_panels_total], absorb(border)
	
	
	local min_bin_temp=`min_bin_big'
	local max_bin_temp=`max_bin_big'
}


  	 forvalues b=`min_bin_temp'/`max_bin_temp' {
	 
		local btemp=100+`b'
		if `b'<0 {
		*	local btemp=100-`b'
		}
			
	 
	 
		local b`btemp'`var'_`type'=0
		local se`btemp'`var'_`type'=0
		 
		 if `b'~=0 {
		
			local b`btemp'`var'_`type'=_b[`btemp'.bin_temp]
			*display "`b`btemp'`var'_`type'"
			local se`btemp'`var'_`type'=_se[`btemp'.bin_temp]
		}
	}

}
*}

if `graphs'==1 {
**** now make graphs
preserve

clear 

local nbins=-`min_bin'+`max_bin'+1

set obs `nbins'

gen bin=_n+`min_bin'-1

gen xaxis=bin*`bin_width' - `bin_width'/2 // because we used ceiling
gen xaxis_big=bin*`bin_width_big' - `bin_width_big'/2 // because we used ceiling

*foreach type in sub tot {
foreach var of local lhs_vars {

*local var CollPerc_t
*local type sub


local title Log Installations Per Capita
local scale ylabel(-.5(.1).8) ysc(r(-.5 .8))

if "`var'"=="CollPerc_t" {
	local title Fraction College Degree
	local scale  ylabel(-0.5(0.25)0.5) ysc(r(-0.5 0.5))
}

if "`var'"=="Pol_t" {
	local title Fraction Democrat
		local scale ylabel(-0.5(0.25)0.5) ysc(r(-0.5 0.5)) // ysc(r(-0.5 0.5))
}

if "`var'"=="sub_ben" {
	local title Expected Subsidy
}

if "`var'"=="tot_ben" {
	local title Expected Monetary Benefit
	local scale ylabel(000(2000)10000) ysc(r(-1000 10000))
}

if "`var'"=="Inc_t" {
	local title Average Household Income
		local scale  ylabel(-40000(20000)40000) ysc(r(-40000 40000))
}


	gen beta`var'_`type'=.
	gen se`var'_`type'=.
	
	
	
	local min_bin_temp=`min_bin'
	local max_bin_temp=`max_bin'
	
	if "`var'"=="lpanels_perc_DS" | "`var'"=="lpanels_perc_DS_sim" | "`var'"=="linstall_perc_DS"  | "`var'"=="linstall_perc_pop_Sim"  {
	
		local min_bin_temp=`min_bin_big'
		local max_bin_temp=`max_bin_big'
	}

	
	
	
	forvalues b=`min_bin_temp'/`max_bin_temp' {
	
	
		local btemp=100+`b'
		if `b'<0 {
		*	local btemp=100-`b'
		}
	
		replace beta`var'_`type'=`b`btemp'`var'_`type'' if bin==`b'
		replace se`var'_`type'=`b`btemp'`var'_`type'' if bin==`b'
	}
	
	gen ub`var'_`type'=beta`var'_`type'+se`var'_`type'*1.96
	gen lb`var'_`type'=beta`var'_`type'-se`var'_`type'*1.96
	
	
twoway ///
(scatter beta`var'_`type' xaxis, msize(large)  ) ///
 /// (rcap lb`var'_`type' ub`var'_`type' xaxis,  lpattern(dash) lcolor(blue) lwidth(medium) ), ///
, yline(0, lpattern(dash) lcolor(black) lwidth(medium) ) graphregion(color(white)) xtitle("Location Relative to Border",size(huge)) ytitle("`title'",size(huge)) ///
legend(off) `scale' xline(0, lpattern(dash))  // ylabel(0(5)15) // ysc(r(0 1)) //  xlabel(2000 2002 2004 2006 2008 2010 2012 2014 2016) ysc(r(`10' `11')) ylabel(`12') xtitle("")

graph export StataGraphs/Scatter`var'_`type'.png, as(png) replace	


twoway (scatter beta`var'_`type' xaxis, msize(large)  )  (rcap lb`var'_`type' ub`var'_`type' xaxis,  lpattern(dash) lcolor(red) lwidth(medium) ) ///
, yline(0, lpattern(dash) lcolor(black) lwidth(medium) ) graphregion(color(white)) xtitle("Location Relative to Border",size(huge)) ytitle("`title'",size(huge)) ///
legend(off) `scale' xline(0, lpattern(dash))  // ylabel(0(5)15) // ysc(r(0 1)) //  xlabel(2000 2002 2004 2006 2008 2010 2012 2014 2016) ysc(r(`10' `11')) ylabel(`12') xtitle("")

graph export StataGraphs/ScatterCI`var'_`type'.png, as(png) replace	


}


foreach var in linstall_perc_DS linstall_perc_pop lpanels_perc_DS {


local title Log Installations Per Capita

if "`var'"=="lpanels_perc_DS" {
	local title Log Panels Per Capita
}

*local var linstall_perc_DS
*local type sub
local dist_temp 50

twoway ///
(scatter beta`var'_Sim_`type' xaxis_big if xaxis_big<`dist_temp' & xaxis_big>-`dist_temp', msize(vlarge) ) (scatter beta`var'_`type' xaxis_big if xaxis_big<`dist_temp' & xaxis_big>-`dist_temp' , msymbol(circle_hollow)  msize(vlarge)  )   ///
 /// (rcap lb`var'_`type' ub`var'_`type' xaxis,  lpattern(dash) lcolor(blue) lwidth(medium) ), ///
, yline(0, lpattern(dash) lcolor(black) lwidth(medium)) graphregion(color(white)) xtitle("Location Relative to Border",size(huge)) ytitle("`title'",size(huge)) ///
legend(order(1 "Predicted " 2 "Actual" )) ylabel(-.5(.1).8) ysc(r(-.5 .8)) xline(0, lpattern(dash))  // ylabel(0(5)15) // ysc(r(0 1)) //  xlabel(2000 2002 2004 2006 2008 2010 2012 2014 2016) ysc(r(`10' `11')) ylabel(`12') xtitle("")

graph export StataGraphs/ScatterComp`var'_`type'.png, as(png) replace	

pause

}




restore
}




**** discontinuity regression to target as structural moment


//no controls
areg linstall tot_ben1000  [aw=number_of_panels_total], absorb(border)

areg linstall tot_ben1000 if distance<200  [aw=number_of_panels_total], absorb(border)

areg linstall tot_ben1000 if distance<100  [aw=number_of_panels_total], absorb(border)

areg linstall tot_ben1000 if distance<50  [aw=number_of_panels_total], absorb(border)


//adding controls
areg linstall tot_ben1000 CollPerc_t Pol_t  [aw=number_of_panels_total], absorb(border)

areg linstall tot_ben1000 CollPerc_t Pol_t if distance<200  [aw=number_of_panels_total], absorb(border)

areg linstall tot_ben1000 CollPerc_t Pol_t if distance<100  [aw=number_of_panels_total], absorb(border)

areg linstall tot_ben1000 CollPerc_t Pol_t  if distance<50  [aw=number_of_panels_total], absorb(border)


areg linstall tot_ben1000 CollPerc_t Pol_t  if distance<50 & novar_`type'==0 [aw=number_of_panels_total], absorb(border) // do we need novar_ty;e?



areg linstall sub_ben CollPerc_t Pol_t stateTax if distance<10  [aw=number_of_panels_total], absorb(border)

areg linstall sub_ben CollPerc_t Pol_t  if distance<10  [aw=number_of_panels_total], absorb(border)

// outreg

gen sub_ben1000=sub_ben/1000

areg linstall sub_ben1000  [aw=number_of_panels_total] if distance<50, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg, replace ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, NO, Border FE, YES, Distance Bandwidth, 50, State Tax Controls, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t [aw=number_of_panels_total] if distance<50, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 50, State Tax Controls, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t stateTax [aw=number_of_panels_total] if distance<50, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 50, State Tax Controls, YES)



areg linstall sub_ben1000  [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, NO, Border FE, YES, Distance Bandwidth, 10, State Tax Controls, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, State Tax Controls, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t stateTax   [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, State Tax Controls, YES)




** more focus on taxes


areg linstall sub_ben1000 CollPerc_t Pol_t [aw=number_of_panels_total] if distance<50, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg2, replace ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 50, Income Tax, NO, Sales Tax, NO, Property Tax, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t stateTax [aw=number_of_panels_total] if distance<50, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg2, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 50, Income Tax, YES, Sales Tax, NO, Property Tax, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal [aw=number_of_panels_total] if distance<50, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg2, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 50, Income Tax, YES, Sales Tax, YES, Property Tax, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg [aw=number_of_panels_total] if distance<50, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg2, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 50, Income Tax, YES, Sales Tax, YES, Property Tax, YES)




areg linstall sub_ben1000 CollPerc_t Pol_t [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg2, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, NO, Sales Tax, NO, Property Tax, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t stateTax [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg2, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, NO, Property Tax, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg2, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, YES, Property Tax, NO)

areg linstall sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg2, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, YES, Property Tax, YES)



// just 10

areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg10, replace ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, NO, Sales Tax, NO, Property Tax, NO)

areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg10, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, NO, Property Tax, NO)

areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg10, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, YES, Property Tax, NO)

areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderReg10, append ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, YES, Property Tax, YES)



sum price_ben sub_ben

gen price_ben1000=price_ben/1000

areg linstall_perc_pop price_ben1000 sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

areg linstall_perc_pop kwh_ben cost_ben unit_ben price_ben CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
//kwh_ben+cost_ben+unit_ben
** export for use in structural model

/*
rename stateTax IncTax
gen SalesTax=avgsalestaxratestatelocal
gen PropTax=propertytaxrateavg



sort tract



foreach var in IncTax SalesTax PropTax {

*	outsheet `var' using ../Data/CleanedData/`var'.csv, replace nonames
}
*/


*** copmaring sexton current vs historical measures

*convert to npv of payments (not per kwh) measured in 1000s of dolalrs
gen npvcurrent=npvwnetmeteringskwh*systemgenerationkwhpermonth*12*20/1000

gen npvhist=npvoftotaltimevaryingincent*systemgenerationkwhpermonth*12*20/1000



areg linstall npvcurrent [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/histcompare.xls, replace ctitle(Model 1) excel keep(npvcurrent ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, NO, Border FE, YES, Distance Bandwidth, 10, Tax Controls, NO)



areg linstall npvhist [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/histcompare.xls, append ctitle(Model 1) excel keep(npvhist ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, NO, Border FE, YES, Distance Bandwidth, 10, Tax Controls, NO)

areg linstall npvcurrent CollPerc_t Pol_t [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/histcompare.xls, append ctitle(Model 1) excel keep(npvcurrent ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, NO)

areg linstall npvhist CollPerc_t Pol_t [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/histcompare.xls, append ctitle(Model 1) excel keep(npvhist ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, NO)

areg linstall npvcurrent CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/histcompare.xls, append ctitle(Model 1) excel keep(npvcurrent ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, YES)

areg linstall npvhist CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/histcompare.xls, append ctitle(Model 1) excel keep(npvhist ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, YES)




areg linstall_perc_pop npvhist CollPerc_t Pol_t [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderRegHist, replace ctitle(Model 1) tex(frag) keep(npvhist ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, NO, Sales Tax, NO, Property Tax, NO)

areg linstall_perc_pop npvhist CollPerc_t Pol_t stateTax [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderRegHist, append ctitle(Model 1) tex(frag) keep(npvhist ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, NO, Property Tax, NO)

areg linstall_perc_pop npvhist CollPerc_t Pol_t stateTax avgsalestaxratestatelocal [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderRegHist, append ctitle(Model 1) tex(frag) keep(npvhist ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, YES, Property Tax, NO)

areg linstall_perc_pop npvhist CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)

outreg2 using StataGraphs/BorderRegHist, append ctitle(Model 1) tex(frag) keep(npvhist ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Income Tax, YES, Sales Tax, YES, Property Tax, YES)


********** Merge in NonMonetary State incentives

drop _merge

merge m:1 state using ../Data/CleanedData/DsireNonMonetaryState.dta

drop if _merge==2 // drops alaska. Keep states that don't have any nonmonetary incentives

foreach var in financing  access  community  other  building {
	replace `var'=0 if `var'==.
	gen d`var'=(`var'>0)
}
	
areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg  [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
outreg2 using StataGraphs/BorderNonMon, replace ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, Yes, Financing Programs, No, Access Rules, No, Building Incentives, No)

areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg financing [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
outreg2 using StataGraphs/BorderNonMon, append ctitle(Model 1) tex(frag) keep(sub_ben1000 financing) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, Yes, Financing Programs, Yes, Access Rules, No, Building Incentives, No)


areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg financing access [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
outreg2 using StataGraphs/BorderNonMon, append ctitle(Model 1) tex(frag) keep(sub_ben1000 financing access) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, Yes, Financing Programs, Yes, Access Rules, Yes, Building Incentives, No)


areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg financing access building [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
outreg2 using StataGraphs/BorderNonMon, append ctitle(Model 1) tex(frag) keep(sub_ben1000 financing access building ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, Yes, Financing Programs, Yes, Access Rules, Yes, Building Incentives, Yes)




*** now just dummies for existence of program


areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg  [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
outreg2 using StataGraphs/BorderNonMonD, replace ctitle(Model 1) tex(frag) keep(sub_ben1000 ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, Yes, Financing Programs, No, Access Rules, No, dbuilding Incentives, No)

areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg dfinancing [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
outreg2 using StataGraphs/BorderNonMonD, append ctitle(Model 1) tex(frag) keep(sub_ben1000 dfinancing) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, Yes, Financing Programs, Yes, Access Rules, No, Building Incentives, No)


areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg dfinancing daccess [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
outreg2 using StataGraphs/BorderNonMonD, append ctitle(Model 1) tex(frag) keep(sub_ben1000 dfinancing daccess) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, Yes, Financing Programs, Yes, Access Rules, Yes, Building Incentives, No)


areg linstall_perc_pop sub_ben1000 CollPerc_t Pol_t stateTax avgsalestaxratestatelocal propertytaxrateavg dfinancing daccess dbuilding [aw=number_of_panels_total] if distance<10, vce(cluster state_fips) absorb(border)
outreg2 using StataGraphs/BorderNonMonD, append ctitle(Model 1) tex(frag) keep(sub_ben1000 dfinancing daccess dbuilding ) nocons /// keep(tot_ben1000 )
addtext(Demographic Controls, YES, Border FE, YES, Distance Bandwidth, 10, Tax Controls, Yes, Financing Programs, Yes, Access Rules, Yes, Building Incentives, Yes)








